﻿using Flee.CalcEngine.PublicTypes;
using Flee.PublicTypes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ComputeLib
{
    class TestEntry
    {
        static void Main()
        {
            CalculationEngine engine = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();
            VariableCollection variables = context.Variables;

            // Add some variables
            variables.Add("x", 100);
            variables.Add("y", 200);
            variables.Add("z", 300);

            // Add an expression to the calculation engine as "a"
            engine.Add("a", "x * 2", context);

            // Add an expression to the engine as "b"
            engine.Add("b", "y + 100", context);

            // Add an expression at "c" that uses the results of "a" and "b"
            engine.Add("c", "a + b", context);

            // Get the value of "c"
            int result = engine.GetResult<int>("c");

            // Update a variable on the "a" expression            
            variables["x"] = 200;

            // Recalculate it
            engine.Recalculate("a");

            // Get the updated result
            result = engine.GetResult<int>("c");
            Console.WriteLine(result);

            ExpressionContext context1 = new ExpressionContext();
            context1.Imports.AddType(typeof(CalculationUitls));
            context1.Variables.Add("a",10);
            IDynamicExpression expression = context1.CompileDynamic("getParams(a)");

            var x = expression.Evaluate();
            Console.WriteLine(x);



            //ExpressionContext context = new ExpressionContext();
            //context.Variables.Add("a", 3);
            //context.Variables.Add("b", 4);

            /*try
            {
                
                IDynamicExpression expression = context.CompileDynamic("a*b");

                
                int v = (int)expression.Evaluate();

                Console.WriteLine(v);
            }
            catch (Flee.PublicTypes.ExpressionCompileException ex)
            {
                
                Console.WriteLine(ex.ToString());
            }*/
            Console.ReadLine();
        }
    }
}
